home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / util / memometr / part02 < prev   
Encoding:
Internet Message Format  |  1990-04-15  |  37.3 KB

  1. Path: wuarchive!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!xanth!cs.odu.edu!Amiga-Request
  2. From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v90i149: MemMometer 2.1 - memory fragmentation gauge, Part02/02
  5. Message-ID: <12222@xanth.cs.odu.edu>
  6. Date: 15 Apr 90 14:51:23 GMT
  7. Sender: tadguy@cs.odu.edu
  8. Reply-To: hull@hao.ucar.edu (Howard Hull)
  9. Lines: 1091
  10. Approved: tadguy@cs.odu.edu (Tad Guy)
  11. X-Mail-Submissions-To: Amiga@cs.odu.edu
  12. X-Post-Discussions-To: comp.sys.amiga
  13.  
  14. Submitted-by: hull@hao.ucar.edu (Howard Hull)
  15. Posting-number: Volume 90, Issue 149
  16. Archive-name: util/memmometer-2.1/part02
  17.  
  18. #!/bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of archive 2 (of 2)."
  25. # Contents:  mm.c
  26. # Wrapped by tadguy@xanth on Sun Apr 15 10:49:57 1990
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'mm.c' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'mm.c'\"
  30. else
  31. echo shar: Extracting \"'mm.c'\" \(35050 characters\)
  32. sed "s/^X//" >'mm.c' <<'END_OF_FILE'
  33. X/* : ai=0 bk=0 ts=8 */
  34. X#include "mm.h"
  35. X
  36. X#define FREEPEN -1L           /* workbench screen default colors */
  37. X#define REQ_WINDOW_WIDTH 319L /* width of SFMem warning requester window */
  38. X#define REQ_WINDOW_HEIGHT 79L /* height of SFMem warning requester window */
  39. X
  40. X#define SOK        0x001f     /* memory allocation control masks */
  41. X#define S1         0x0001
  42. X#define S2         0x0002
  43. X#define S4         0x0004
  44. X#define S8         0x0008
  45. X#define SA         0x0010
  46. X#define C1         0xfffe
  47. X#define C2         0xfffd
  48. X#define C4         0xfffb
  49. X#define C8         0xfff7
  50. X#define CA         0xffef
  51. X#define AARRRGH    20L
  52. X
  53. X#define EXTENSION  16L         /* allocation request increment */
  54. X
  55. X#define FRAGS FALSE                          /* frags mode control boolian */
  56. X#define WARPS TRUE                     /* warps mode control boolian */
  57. X#define EVENMASK 0x7ffffffe           /* used to prevent odd address traps */
  58. X#define CLIHEIGHT 200L                             /* window scaling stuff */
  59. X#define SIZEGAD 9L
  60. X#define DRAGBAR 10L
  61. X#define BORDER 2L
  62. X#define WINW 16L                                   /* initial window width */
  63. X#define WINH (long)(CLIHEIGHT - SIZEGAD - DRAGBAR)   /* initial win height */
  64. X#define MINH 81L                              /* shortest allowable window */
  65. X#define MAXH 576L                              /* longest allowable window */
  66. X#define BART 1L                               /* title bar F text location */
  67. X#define BARH (long)(WINH - SIZEGAD - DRAGBAR)                /* bar height */
  68. X#define BARS (long)(BARH + 1)        /* number of memory items to allocate */
  69. X#define BARB (long)(BARH + DRAGBAR - 1)        /* bottom of mercury column */
  70. X#define BARE (long)(BARB + BORDER)              /* bar end E text position */
  71. X#define BARW (long)(((WINW - (2 * BORDER)) / 3) - 1)  /* 3 memfragmometers */
  72. X#define LEFT BORDER                   /* SLOW : since we're syncopated, we */
  73. X#define MIDDLE (LEFT + BARW + 1)      /* SLOW-FAST : do it going from bar  */
  74. X#define RIGHT (MIDDLE + BARW + 1)     /* FAST :to bar at an irregular pace */
  75. X#define RTEXT - 4L        /* offset for three char E/F text from left edge */
  76. X#define STARTVAL 64L    /* start by getting enough storage for a few frags */
  77. X
  78. X/* typedef short BOOL */        /* this is in include/exec/types.h */
  79. X
  80. Xstruct IntuitionBase *IntuitionBase=NULL ;
  81. Xstruct Window *window ;
  82. Xstruct IntuiMessage *message;
  83. X/* struct IntuiMessage *GetMsg(); */        /* in functions.h */
  84. X
  85. Xstruct GfxBase *GfxBase=NULL ;
  86. X
  87. Xstruct IOStdReq *timermsg=NULL;
  88. Xstruct MsgPort *timerport=NULL;
  89. XULONG  timerbit=NULL;
  90. X
  91. X
  92. Xextern void InitProjItems();        /* this stuff is in the mminit section */
  93. Xextern void InitSetupItems();
  94. Xextern void InitPrioItems();
  95. Xextern void InitChipItems();
  96. Xextern void InitChipAItems();
  97. Xextern void InitSFItems();
  98. Xextern void InitSFAItems();
  99. Xextern void InitFastItems();
  100. Xextern void InitFastAItems();
  101. Xextern void InitMenu();
  102. Xextern void StartMenus();
  103. X
  104. XBOOL p_mode = FRAGS;          /* preset frags mode = 0, warps mode = 1 */
  105. X                              /* note: mode preset used as request for */
  106. X                              /*       change to warps mode after the  */
  107. X                              /*       first pass with frags mode set! */
  108. Xlong p_rate = 2;              /* preset sample interval, secs see menu */
  109. Xlong p_priority = 0;          /* preset priority, range -128 to +127   */
  110. X                              /* note: pri greater than zero is risky! */
  111. X                              /* keep in mind AmigaDOS priorities:     */
  112. X                              /* input.device 20, FileSystem 10, and   */
  113. X                              /* trackdisk.device, CON: 5 also if MM   */
  114. X                              /* is started from a CLI without the Run */
  115. X                              /* then that CLI inherits MM's priority! */
  116. Xlong p_chip = 512;            /* preset chip mem size, kbytes see menu */
  117. Xlong p_chipa = 0;             /* preset chip mem address, kb  see menu */
  118. Xlong p_sf = 0;                /* preset slowfast mem size, kb see menu */
  119. Xlong p_sfa = 0x3000;          /* preset slowfast mem addr, kb see menu */
  120. Xlong p_fast = 0;              /* preset fast mem size, mbytes see menu */
  121. Xlong p_fasta = 2;             /* preset fast mem addr, mbytes see menu */
  122. X
  123. Xstatic BOOL mode;                    /* uninitialized for mode control */
  124. Xstatic BOOL mmode;                   /* uninitialized for mode  menu */
  125. Xstatic long delayval;                /* uninitialized for delay menu */
  126. Xstatic long priority;                /* uninitialized for priority menu */
  127. Xstatic long lastpri;                 /* uninitialized for priority incr */
  128. Xstatic long cmemsize;                /* uninitialized for chip  menu */
  129. Xstatic long cmembase;                /* uninitialized for chipa menu */
  130. Xstatic long sfmemsize;               /* uninitialized for sf    menu */
  131. Xstatic long sfmembase;               /* uninitialized for sfa   menu */
  132. Xstatic long fmemsize;                /* uninitialized for fast  menu */
  133. Xstatic long fmembase;                /* uninitialized for fasta menu */
  134. X
  135. Xstatic USHORT log ;                  /* memory allocation success flags */
  136. Xstatic BOOL things_are_cool = TRUE ; /* tells when to close the window  */
  137. Xstatic BOOL intsig = FALSE ;         /* intuition message detector */
  138. Xstatic USHORT chgflag = TRUE ;       /* menu request to adjust columns */
  139. Xstatic long chip[3], fast[3] ;       /* place to keep mem header pointers */
  140. Xstatic ULONG  *chunkv ;              /* demand allocated for frag chunks */
  141. Xstatic ULONG  *sizev ;               /* demand allocated for frag sizes */
  142. Xstatic ULONG  *csum ;                /* a col's height worth of checksums */
  143. Xstatic ULONG  *oldcsum ;             /* same height worth of old checksums */
  144. Xstatic USHORT *cell;                 /* 1 cell per pixel height of mercury */
  145. Xstatic long xl, xr ;                 /* used to Draw() memometer segments */
  146. Xstatic long frags = STARTVAL ;       /* # of demand allocated frag items */
  147. Xstatic long warps = BARS ;           /* # of demand allocated column items */
  148. Xstatic long barh = BARH ;            /* EVEN #'d height of mercury column */
  149. Xstatic long barb = BARB ;            /* bottom position of mercury column */
  150. X
  151. X/* struct RastPort *rp ; */          /* wonder why we don't need this... ? */
  152. X
  153. X
  154. Xstatic struct TextAttr myfont = {
  155. X   (STRPTR) "topaz.font",
  156. X   TOPAZ_EIGHTY,
  157. X   0,
  158. X   0
  159. X};
  160. X/* E newsize gadget refresh text */ 
  161. Xstatic char ebuf[4] = " E " ;
  162. Xstatic struct IntuiText e_text = { 
  163. X   BLUP, WHTP,
  164. X   JAM2, 
  165. X   0, BARE,
  166. X   &myfont,
  167. X   (UBYTE *)ebuf, 
  168. X   NULL 
  169. X};
  170. X/* F title refresh text */
  171. Xstatic char fbuf[4] = " F " ;
  172. Xstatic struct IntuiText f_text = {
  173. X   BLUP, WHTP,
  174. X   JAM2,
  175. X   0, BART,
  176. X   &myfont,
  177. X   (UBYTE *)fbuf,
  178. X   &e_text
  179. X};
  180. Xstatic struct NewWindow newwindow = {
  181. X   0,                                        /* left edge */
  182. X   10,                                       /* top edge */
  183. X   WINW,                                     /* width */
  184. X   WINH,                                     /* height */
  185. X   0,                                        /* detail pen */
  186. X   1,                                        /* block pen */
  187. X   MENUPICK | NEWSIZE,                       /* messages */
  188. X/* WINDOWDEPTH | WINDOWCLOSE */              /* don't use these gads */
  189. X   WINDOWDRAG | WINDOWSIZING | SMART_REFRESH,   /* add a few gadgets */
  190. X   NULL,                                     /* no custom gadgets */
  191. X   NULL,                                     /* default checkmark */
  192. X   (UBYTE *)"F",                             /* title */
  193. X   NULL,                                     /* initialize this! */
  194. X   NULL,                                     /* use screen bitmap */
  195. X   WINW, MINH, WINW, MAXH,                   /* min and max sizes */
  196. X   WBENCHSCREEN } ;                          /* use workbench screen */
  197. X
  198. Xvoid initmenus()
  199. X{
  200. X   (void) InitProjItems();              /* Initialize the menu items */
  201. X   (void) InitSetupItems();
  202. X   (void) InitPrioItems();
  203. X   (void) InitChipItems();
  204. X   (void) InitChipAItems();
  205. X   (void) InitSFItems();
  206. X   (void) InitSFAItems();
  207. X   (void) InitFastItems();
  208. X   (void) InitFastAItems();
  209. X   (void) InitMenu();
  210. X   (void) StartMenus();
  211. X   }
  212. X
  213. Xvoid handle_MENUPICK( class, code )
  214. Xunsigned long class;
  215. Xunsigned int code;
  216. X{
  217. X    unsigned int menunum, itemnum, subnum;
  218. X
  219. X    if (code == MENUNULL) return;
  220. X
  221. X    menunum = MENUNUM( code );
  222. X    itemnum = ITEMNUM( code );
  223. X    subnum  = SUBNUM( code );
  224. X    chgflag = TRUE;
  225. X    switch( menunum ) {
  226. X        case 0:
  227. X        switch( itemnum ) {
  228. X            case 0:
  229. X            WindowToFront(window);
  230. X            break;
  231. X
  232. X            case 1:
  233. X            WindowToBack(window);
  234. X            break;
  235. X
  236. X            case 2:
  237. X            things_are_cool = FALSE;  /* Quit */
  238. X            break;
  239. X            } /* end of switch ( Project itemnum ) */
  240. X        break;
  241. X
  242. X        case 1:
  243. X        switch( itemnum ) {
  244. X            case 0:
  245. X            switch( subnum ) {
  246. X                case 0:
  247. X                mode = FRAGS ;  /* Frags mode */
  248. X                break;
  249. X
  250. X                case 1:
  251. X                mmode = TRUE ;  /* Warps request */
  252. X                break;
  253. X                /* end of switch ( Mode subnum ) */
  254. X                }
  255. X            break;       
  256. X            case 1:
  257. X            switch( subnum ) {
  258. X                case 0:
  259. X                delayval = 1;
  260. X                break;
  261. X
  262. X                case 1:
  263. X                delayval = 2;
  264. X                break;
  265. X
  266. X                case 2:
  267. X                delayval = 5;
  268. X                break;
  269. X
  270. X                case 3:
  271. X                delayval = 10;
  272. X                break;
  273. X                /* end of switch ( Freq subnum ) */
  274. X                }
  275. X            break;       
  276. X            /* end of switch ( Setup itemnum ) */
  277. X            }
  278. X        break;
  279. X
  280. X        case 2:
  281. X        switch( itemnum ) {
  282. X            case  0:
  283. X            priority = lastpri;
  284. X            break;
  285. X
  286. X            case  1:
  287. X            priority = priority - 1;
  288. X            break;
  289. X
  290. X            case  2:
  291. X            priority = priority + 1;
  292. X            break;
  293. X
  294. X            case  3:
  295. X            priority = -99;
  296. X            lastpri = priority;
  297. X            break;
  298. X
  299. X            case  4:
  300. X            priority = -75;
  301. X            lastpri = priority;
  302. X            break;
  303. X
  304. X            case  5:
  305. X            priority = -50;
  306. X            lastpri = priority;
  307. X            break;
  308. X
  309. X            case  6:
  310. X            priority = -25;
  311. X            lastpri = priority;
  312. X            break;
  313. X
  314. X            case  7:
  315. X            priority = -20;
  316. X            lastpri = priority;
  317. X            break;
  318. X
  319. X            case  8:
  320. X            priority = -15;
  321. X            lastpri = priority;
  322. X            break;
  323. X
  324. X            case  9:
  325. X            priority = -10;
  326. X            lastpri = priority;
  327. X            break;
  328. X
  329. X            case 10:
  330. X            priority =  -5;
  331. X            lastpri = priority;
  332. X            break;
  333. X
  334. X            case 11:
  335. X            priority =   0;
  336. X            lastpri = priority;
  337. X            break;
  338. X
  339. X            case 12:
  340. X            priority =   5;
  341. X            lastpri = priority;
  342. X            break;
  343. X
  344. X            case 13:
  345. X            priority =  10;
  346. X            lastpri = priority;
  347. X            break;
  348. X
  349. X            case 14:
  350. X            priority =  15;
  351. X            lastpri = priority;
  352. X            break;
  353. X
  354. X            case 15:
  355. X            priority =  20;
  356. X            lastpri = priority;
  357. X            break;
  358. X            }
  359. X            /* end of switch ( Priority itemnum ) */
  360. X        break;
  361. X
  362. X        case 3:
  363. X        switch( itemnum ) {
  364. X            case 0:
  365. X            cmemsize = 0x000000;
  366. X            break;
  367. X
  368. X            case 1:
  369. X            cmemsize = 0x040000;
  370. X            break;
  371. X
  372. X            case 2:
  373. X            cmemsize = 0x080000;
  374. X            break;
  375. X
  376. X            case 3:
  377. X            cmemsize = 0x100000;
  378. X            break;
  379. X
  380. X            case 4:
  381. X            cmemsize = 0x200000;
  382. X            break;
  383. X            }
  384. X            /* end of switch ( Chip Size itemnum ) */
  385. X        break;
  386. X
  387. X        case 4:
  388. X        switch( itemnum ) {
  389. X            case 0:
  390. X            cmembase = 0x000000;
  391. X            break;
  392. X
  393. X            case 1:
  394. X            cmembase = 0x040000;
  395. X            break;
  396. X
  397. X            case 2:
  398. X            cmembase = 0x080000;
  399. X            break;
  400. X
  401. X            case 3:
  402. X            cmembase = 0x100000;
  403. X            break;
  404. X            }
  405. X            /* end of switch ( Chip Addr itemnum ) */
  406. X        break;
  407. X
  408. X        case 5:
  409. X        if (mode == WARPS)  mmode = TRUE ;
  410. X        switch( itemnum ) {
  411. X            case 0:
  412. X            sfmemsize = 0x000000;
  413. X            break;
  414. X
  415. X            case 1:
  416. X            sfmemsize = 0x080000;
  417. X            break;
  418. X
  419. X            case 2:
  420. X            sfmemsize = 0x100000;
  421. X            break;
  422. X
  423. X            case 3:
  424. X            sfmemsize = 0x180000;
  425. X            break;
  426. X            }
  427. X            /* end of switch ( SF Size itemnum ) */
  428. X        break;
  429. X
  430. X        case 6:
  431. X        if (mode == WARPS)  mmode = TRUE ;
  432. X        switch( itemnum ) {
  433. X            case 0:
  434. X            sfmembase = 0xc00000;
  435. X            break;
  436. X
  437. X            case 1:
  438. X            sfmembase = 0xc80000;
  439. X            break;
  440. X
  441. X            case 2:
  442. X            sfmembase = 0xd00000;
  443. X            break;
  444. X
  445. X            case 3:
  446. X            sfmembase = 0xd80000;
  447. X            break;
  448. X            }
  449. X            /* end of switch ( SF Addr itemnum ) */
  450. X        break;
  451. X
  452. X        case 7:
  453. X        switch( itemnum ) {
  454. X            case 0:
  455. X            fmemsize = 0x000000;
  456. X            break;
  457. X
  458. X            case 1:
  459. X            fmemsize = 0x080000;
  460. X            break;
  461. X
  462. X            case 2:
  463. X            fmemsize = 0x100000;
  464. X            break;
  465. X
  466. X            case 3:
  467. X            fmemsize = 0x200000;
  468. X            break;
  469. X
  470. X            case 4:
  471. X            fmemsize = 0x400000;
  472. X            break;
  473. X
  474. X            case 5:
  475. X            fmemsize = 0x600000;
  476. X            break;
  477. X
  478. X            case 6:
  479. X            fmemsize = 0x800000;
  480. X            break;
  481. X            }
  482. X            /* end of switch ( Fast Size itemnum ) */
  483. X        break;
  484. X
  485. X        case 8:
  486. X        if (mode == WARPS)  mmode = TRUE ;
  487. X        switch( itemnum ) {
  488. X            case 0:
  489. X            fmembase = 0x200000;
  490. X            break;
  491. X
  492. X            case 1:
  493. X            fmembase = 0x300000;
  494. X            break;
  495. X
  496. X            case 2:
  497. X            fmembase = 0x400000;
  498. X            break;
  499. X
  500. X            case 3:
  501. X            fmembase = 0x500000;
  502. X            break;
  503. X
  504. X            case 4:
  505. X            fmembase = 0x600000;
  506. X            break;
  507. X
  508. X            case 5:
  509. X            fmembase = 0x700000;
  510. X            break;
  511. X
  512. X            case 6:
  513. X            fmembase = 0x800000;
  514. X            break;
  515. X
  516. X            case 7:
  517. X            fmembase = 0x900000;
  518. X            break;
  519. X            }
  520. X            /* end of switch ( Fast Addr itemnum ) */
  521. X        break;
  522. X        }
  523. X        /* end of switch ( menunum ) */
  524. X}
  525. X
  526. Xvoid wrack_sploot() /* this subprogram cashes in the chips in bad times */
  527. X    {
  528. X    if (log != 0) {
  529. X        if (log & SA) {
  530. X            (void) FreeMem(oldcsum, (long)(sizeof(ULONG) * warps)) ;
  531. X            log = log & CA ;
  532. X            }
  533. X        if (log & S8) {
  534. X            (void) FreeMem(csum, (long)(sizeof(ULONG) * warps)) ;
  535. X            log = log & C8 ;
  536. X            }
  537. X        if (log & S4)  {
  538. X            (void) FreeMem(sizev, (long)(sizeof(long) * frags)) ;
  539. X            log = log & C4 ;
  540. X            }
  541. X        if (log & S2)  {
  542. X            (void) FreeMem(chunkv, (long)(sizeof(long) * frags)) ;
  543. X            log = log & C2 ;
  544. X            }
  545. X        if (log & S1) {
  546. X            (void) FreeMem(cell, (long)(sizeof(USHORT) * warps)) ;
  547. X            log = log & C1 ;
  548. X            }
  549. X        frags = 0;
  550. X        warps = 0;
  551. X        }
  552. X}
  553. X
  554. XSetTimer(sec, micro, timermsg)
  555. XULONG sec, micro;
  556. Xstruct IOStdReq *timermsg;
  557. X/* This routine simply sets the timer to interrupt us after secs.micros */
  558. X{
  559. X    timermsg->io_Command = TR_ADDREQUEST;    /* add a new timer request */
  560. X    timermsg->io_Actual = sec;    /* seconds */
  561. X    timermsg->io_Length = micro;    /* microseconds */
  562. X    SendIO(timermsg);   /* post a request to the timer */
  563. X}
  564. X
  565. Xvoid cleanup() {
  566. X    if (timerport) {
  567. X        Wait(timerbit);
  568. X        GetMsg(timerport);
  569. X        CloseDevice(timermsg);
  570. X        DeleteStdIO(timermsg);
  571. X        DeletePort(timerport);
  572. X        }
  573. X    if (GfxBase)        CloseLibrary(GfxBase) ;
  574. X    if (window)         CloseWindow(window) ;
  575. X    if (IntuitionBase)  CloseLibrary(IntuitionBase) ;
  576. X    wrack_sploot() ;
  577. X    exit(AARRRGH) ;
  578. X}
  579. X
  580. Xvoid inittimer() {
  581. X    if(!(timerport = (struct MsgPort *)CreatePort(0L, 0L)))cleanup();
  582. X    if(!(timermsg = (struct IOStdReq *)CreateStdIO(timerport)))cleanup();
  583. X    if (OpenDevice(TIMERNAME, UNIT_VBLANK, timermsg, 0L))cleanup();
  584. X
  585. X    timerbit = 1L << timerport->mp_SigBit ;
  586. X    SetTimer(1L, 0L, timermsg); /* set for first message */
  587. X}
  588. X
  589. Xvoid handle_NEWSIZE() /* short term allocations cashed in then realloc'd */
  590. X    {                 /* when user hits gadget but doesn't resize window */
  591. X    if (log & SA)  {
  592. X        (void) FreeMem(oldcsum, (long)(sizeof(ULONG) * warps)) ;
  593. X        log = log & CA ;
  594. X        }
  595. X    if (log & S8)  {
  596. X        (void) FreeMem(csum, (long)(sizeof(ULONG) * warps)) ;
  597. X        log = log & C8 ;
  598. X        }
  599. X    if (log & S1)  {
  600. X        (void) FreeMem(cell, (long)(sizeof(USHORT) * warps)) ;
  601. X        log = log & C1 ;
  602. X    barh = window->Height - SIZEGAD - DRAGBAR ;  /* recalculate height */
  603. X    barb = window->Height - SIZEGAD - 1 ; /* get new bar base position */
  604. X    warps = barh + 1 ;       /* number of storage cells to be reserved */
  605. X    if ((cell = (USHORT *)AllocMem((long)sizeof(USHORT) * warps,
  606. X                                    MEMF_PUBLIC)) != 0L ) log = log | S1;
  607. X    if ((csum = (ULONG *)AllocMem((long)sizeof(ULONG) * warps,
  608. X                                    MEMF_PUBLIC)) != 0L ) log = log | S8;
  609. X    if ((oldcsum = (ULONG *)AllocMem((long)sizeof(ULONG) * warps,
  610. X                                    MEMF_PUBLIC)) != 0L ) log = log | SA;
  611. X    if (log != SOK)  {      /* bail out if we didn't get an allocation */
  612. X        wrack_sploot() ;
  613. X        things_are_cool = FALSE ;     /* tell _main that we're leaving */
  614. X        }
  615. X    e_text.TopEdge = barb + BORDER ;        /* set the E text position */
  616. X    }
  617. X}
  618. X
  619. Xvoid handle_MESSAGES()  {
  620. X    unsigned long class;
  621. X    unsigned int code, qual;
  622. X
  623. X    /* Wait (1L << window->UserPort->mp_SigBit); this is rediculous! */
  624. X    while ((message=(struct IntuiMessage *)GetMsg(window->UserPort))
  625. X                                                                != 0L) {
  626. X        class = message->Class ;
  627. X        code = message->Code ;
  628. X        qual = message->Qualifier ;
  629. X        ReplyMsg ;
  630. X        switch( class ) {
  631. X
  632. X            case NEWSIZE:
  633. X            intsig = TRUE ;                     /* resize when done here */
  634. X            break ;
  635. X
  636. X            case MENUPICK:
  637. X            handle_MENUPICK( class, code ) ;    /* do menus ASAP */
  638. X            break ;
  639. X            }
  640. X        }
  641. X}
  642. X
  643. Xvoid memometer()                /* this subprogram draws the bar graphs */
  644. X    {
  645. X    long i;
  646. X    long y;
  647. X
  648. X    (void) handle_MESSAGES() ;  /* go see if the user wants anything */
  649. X    i = 0 ;
  650. X    while ((i < barh) && (intsig == FALSE)) {
  651. X        y = barb - i ;
  652. X        SetAPen(window->RPort, (long)cell[i]);
  653. X        Move(window->RPort, xl, y);
  654. X        Draw(window->RPort, xr, y);
  655. X        i++ ;
  656. X        }
  657. X}
  658. X
  659. Xvoid shake()    /* this subprogram slings down the mercury column */
  660. X    {
  661. X    int i;
  662. X
  663. X    for (i = 0; i < barh; i++)  {
  664. X        cell[i] = YELP ;
  665. X        }
  666. X}
  667. X
  668. Xvoid lockout()  /* this subprogram renders a whole column in border colors */
  669. X    {
  670. X    (void) handle_MESSAGES() ;        /* go see if the user wants anything */
  671. X    if (intsig == FALSE)  {
  672. X        SetAPen(window->RPort, WHTP) ;          /* set in the border color */
  673. X        RectFill(window->RPort, xl, (barb - barh + 1), xr, barb) ; /* fill */
  674. X        }
  675. X}
  676. X
  677. Xvoid updatewarps( wf, membase, memseg )  /* this subprogram finds changes */
  678. Xshort wf;
  679. Xlong membase, memseg ;
  680. X    {
  681. X    register long i ;
  682. X    register ULONG r ;
  683. X    register ULONG delta ;
  684. X    register ULONG *a ;
  685. X
  686. X    if (memseg == 0) {
  687. X        (void) lockout() ;
  688. X        return ;
  689. X        }
  690. X    else (void) shake() ;
  691. X
  692. X    delta = (ULONG)(memseg & EVENMASK) ;  /* try to avoid odd address trap */
  693. X    r = (ULONG)(membase & EVENMASK) ;     /* prefer wrong address to death */
  694. X    for (i = 0; i < barh; i++)  {
  695. X        csum[i] = 0 ;
  696. X        }
  697. X    for (i = 0; i < barh; i++)  {
  698. X        for (a = (ULONG *)r; a < (ULONG *)(r + delta); a++)  {
  699. X            csum[i] ^= *a ;
  700. X            }
  701. X        if (oldcsum[i] != 0)  cell[i] ^= GRNP ;       /* enters with pens  */
  702. X        if (csum[i] == oldcsum[i])  cell[i] &= GRNP ; /* all on, condition */
  703. X        if (csum[i] == 0)  cell[i] ^= CYNP ;          /* detected clears a */
  704. X        if (oldcsum[i] == 0xffffffff) cell[i] = CYNP ;/* pen; at the end a */
  705. X        if (csum[i] == 0xffffffff)  cell[i] = GRNP ;  /* logical true sets */
  706. X        oldcsum[i] = csum[i] ;                        /* a pen not yet set */
  707. X        r += delta ;
  708. X        }
  709. X    (void) memometer();
  710. X}
  711. X
  712. Xvoid updatescreen( wf, membase, memseg )
  713. Xshort wf;
  714. Xlong membase, memseg;
  715. X    {
  716. X    register long size ;
  717. X    register struct MemHeader *hdr ;
  718. X    register struct MemChunk *chunk ;
  719. X    extern struct ExecBase *SysBase ;
  720. X    register long *which ;                /* active memlist chunk pointer */
  721. X    register long newlimit ;  /* number of chunks, incl 1 null chunk, + 1 */
  722. X    register long newfrags ;  /* number of chunks, incl null chunks, + 1  */
  723. X    long newsize ;  /* size of next request for chunkv/sizev memory, + 1  */
  724. X    int i, j, k, l ;
  725. X    int length ;       /* length is number of chunks to be processed, + 1 */
  726. X    BOOL cf, nf ;      /* cf is "chip flag" nf is "null chunk found" flag */
  727. X
  728. X    if (memseg == 0) {
  729. X        (void) lockout() ;
  730. X        return;
  731. X        }
  732. X    else (void) shake() ;
  733. X
  734. X    for (i = 0; i < 3; i++) {
  735. X        chip[i] = 0;
  736. X        fast[i] = 0;
  737. X        }
  738. X    for (i = 0; i < frags; i++) {
  739. X        chunkv[i] = 0;
  740. X        sizev[i] = 0;
  741. X        }
  742. X    newfrags = 0 ;
  743. X    newlimit = 0 ;
  744. X    nf = FALSE;
  745. X    Forbid() ;
  746. X    hdr = (struct MemHeader *) SysBase->MemList.lh_Head ;
  747. X    while (hdr->mh_Node.ln_Succ) {
  748. X        if (hdr->mh_Attributes & MEMF_CHIP) {
  749. X            which = chip ;
  750. X            cf = TRUE;
  751. X            }
  752. X        else {
  753. X            which = fast ;
  754. X            cf = FALSE;
  755. X            }
  756. X        if (((cf == TRUE) && (wf == 0)) || ((cf == FALSE) && (wf > 0)))  {
  757. X            for (chunk = hdr->mh_First; chunk; chunk = chunk->mc_Next) {
  758. X                if (which[1] < frags)  chunkv[which[1]++] = (unsigned long)chunk ;
  759. X                size = chunk->mc_Bytes ;
  760. X                if (which[2] < frags)  sizev[which[2]++] = (unsigned long)size;
  761. X                *which += size ;
  762. X                if (nf == FALSE)  {
  763. X                    newlimit++ ;
  764. X                    if (chunkv[newfrags] == NULL)  {
  765. X                        nf = TRUE;
  766. X                        }
  767. X                    }
  768. X                newfrags++ ;
  769. X            }
  770. X        }
  771. X        hdr = (struct MemHeader *)hdr->mh_Node.ln_Succ ;
  772. X        }
  773. X    Permit() ;
  774. X    length = frags ;
  775. X    if (newlimit < frags)  length = newlimit ;
  776. X    for (i = 0; i < length; i++)  {
  777. X        chunkv[i] -= membase;   /* chunkv is now array offset from base   */
  778. X        sizev[i] += chunkv[i];  /* and sizev is now address of array top  */
  779. X        chunkv[i] = chunkv[i] / memseg;  /* this is the number of pixels  */
  780. X        sizev[i] = sizev[i] / memseg;       /* and this is the top pixel  */
  781. X        if (chunkv[i] < 0) chunkv[i] = 0 ;  /* we do some bounds checking */
  782. X        if (sizev[i] < 0) sizev[i] = 0 ;
  783. X        if (chunkv[i] >= barh) chunkv[i] = barh - 1 ;
  784. X        if (sizev[i] >= barh) sizev[i] = barh - 1 ;
  785. X        if (sizev[i] - chunkv[i] < 0)  sizev[i] = chunkv[i] ;
  786. X        j = chunkv[i] ; /* from now on it will be less confusing if */
  787. X        k = sizev[i] ;  /* we assign some variables for this stuff  */
  788. X        if (sizev[i] - chunkv[i] == 0)  {
  789. X            cell[j] &= BLUP ;
  790. X            }
  791. X        else  {
  792. X            for (l = j; l < k; l++)  {
  793. X                cell[l] &= BLKP ;
  794. X                }
  795. X            }
  796. X        }
  797. X    (void) memometer();
  798. X    newsize = frags ;
  799. X    while (newsize < newlimit)  {
  800. X        newsize += EXTENSION ;
  801. X        }
  802. X    if (newlimit > frags)  {
  803. X        (void) FreeMem(chunkv, (long)(sizeof(long) * frags));
  804. X        if ((chunkv = (unsigned long *)AllocMem((long)sizeof(long) * newsize,
  805. X                                        MEMF_PUBLIC)) == 0L )  {
  806. X            log = log & C2 ;
  807. X            }
  808. X        (void) FreeMem(sizev, (long)(sizeof(long) * frags));
  809. X        if ((sizev = (unsigned long *)AllocMem((long)sizeof(long) * newsize,
  810. X                                        MEMF_PUBLIC)) == 0L ) {
  811. X            (void) FreeMem(chunkv, (long)(sizeof(long) * newsize));
  812. X            log = log & C4 ;
  813. X            }
  814. X        if (log != SOK)  {
  815. X            wrack_sploot() ;
  816. X            things_are_cool = FALSE ;
  817. X            }
  818. X        else frags = newsize ;
  819. X        }
  820. X}
  821. X
  822. Xmain() {
  823. X    static struct IntuiText bodyText0 =
  824. X        {BLUP, WHTP, JAM2, 58, 10, NULL, NULL, NULL};
  825. X    static struct IntuiText bodyText1 =
  826. X        {BLUP, WHTP, JAM2, 42, 20, NULL, NULL, NULL};
  827. X    static struct IntuiText bodyText2 =
  828. X        {BLUP, WHTP, JAM2, 50, 30, NULL, NULL, NULL};
  829. X    static struct IntuiText positiveText =
  830. X        {BLUP, WHTP, JAM2, 7, 3, NULL, NULL, NULL};
  831. X    static struct IntuiText negativeText =
  832. X        {BLUP, WHTP, JAM2, 7, 3, NULL, NULL, NULL};
  833. X    struct IntuiMessage *message;
  834. X    ULONG class;
  835. X    USHORT code;
  836. X    ULONG wakeupbits;
  837. X    long syspri;
  838. X    char *nptr;
  839. X    struct Task *mmtcb;
  840. X    char oldpri;
  841. X    int t;
  842. X    int i;
  843. X    USHORT colflags;     /* keeps track of column positions and counts */
  844. X    USHORT left;         /* left   column, left edge */
  845. X    USHORT middle;       /* middle column, left edge */
  846. X    USHORT right;        /* right  column, left edge */
  847. X    USHORT barw;         /* width of each mercury column */
  848. X    USHORT wf;           /* memometer window current column number */
  849. X    long cmemseg;
  850. X    long sfmemseg;
  851. X    long fmemseg;
  852. X    long membase;
  853. X    long memseg;
  854. X    long memsize;
  855. X
  856. X    bodyText0.IText = (UBYTE *) "WARNING! CRASH POSSIBLE";
  857. X    bodyText1.IText = (UBYTE *) "MENU MEMORY SELECTIONS MUST";
  858. X    bodyText2.IText = (UBYTE *) "REFERENCE EXISTING MEMORY";
  859. X    bodyText0.NextText = &bodyText1;
  860. X    bodyText1.NextText = &bodyText2;
  861. X    positiveText.IText = (UBYTE *) "Risk It";
  862. X    negativeText.IText = (UBYTE *) "Retreat";
  863. X
  864. X    log = 0 ;
  865. X    if ((cell = (USHORT *)AllocMem((long)sizeof(USHORT) * BARS,
  866. X                                        MEMF_PUBLIC)) != 0L ) log = log | S1;
  867. X    if ((chunkv = (ULONG *)AllocMem((long)sizeof(ULONG) * STARTVAL,
  868. X                                        MEMF_PUBLIC)) != 0L ) log = log | S2;
  869. X    if ((sizev = (ULONG *)AllocMem((long)sizeof(ULONG) * STARTVAL,
  870. X                                        MEMF_PUBLIC)) != 0L ) log = log | S4;
  871. X    if ((csum = (ULONG *)AllocMem((long)sizeof(ULONG) * BARS,
  872. X                                        MEMF_PUBLIC)) != 0L ) log = log | S8;
  873. X    if ((oldcsum = (ULONG *)AllocMem((long)sizeof(ULONG) * BARS,
  874. X                                        MEMF_PUBLIC)) != 0L ) log = log | SA;
  875. X    if (log != SOK)  {
  876. X        wrack_sploot() ;
  877. X        exit(AARRRGH) ;
  878. X        }
  879. X    if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary(
  880. X            "intuition.library",33L)) != NULL &&
  881. X            (window=OpenWindow(&newwindow)) != NULL)  {
  882. X        if ((GfxBase = (struct GfxBase *)OpenLibrary(
  883. X                "graphics.library", 0L)) != NULL)  { 
  884. X            (void) initmenus();
  885. X            /* rp = window->RPort ; */
  886. X            inittimer();
  887. X            wf = 0;
  888. X            mmode = FALSE ;
  889. X            mode = FRAGS ;
  890. X            delayval = p_rate ;
  891. X            priority = p_priority ;
  892. X            if (priority > 0)  priority = 0 ;
  893. X            lastpri = priority ;
  894. X            syspri = priority ;
  895. X            nptr = NULL ;
  896. X            mmtcb = FindTask( nptr ) ;
  897. X            oldpri = SetTaskPri( mmtcb, syspri ) ;
  898. X            cmemsize = p_chip << 10 ;
  899. X            cmembase = p_chipa << 10 ;
  900. X            sfmemsize = p_sf << 10 ;
  901. X            sfmembase = p_sfa << 10 ;
  902. X            if (p_fast >= 512)  fmemsize = p_fast << 10 ;
  903. X            else fmemsize = p_fast << 20 ;
  904. X            fmembase = p_fasta << 20 ;
  905. X            while (things_are_cool == TRUE) {
  906. X                if (chgflag != 0)  {
  907. X                    chgflag = 0 ;
  908. X                    colflags = 0 ;
  909. X                    if (cmemsize != 0)  colflags = colflags | (1 << 0) ;
  910. X                    if (sfmemsize != 0)  colflags = colflags | (1 << 1) ;
  911. X                    if (fmemsize != 0)  colflags = colflags | (1 << 2) ;
  912. X                    switch ( colflags ) {
  913. X                        case 0:
  914. X                        barw = (WINW - (2 * BORDER)) - 1 ;
  915. X                        left = LEFT ;
  916. X                        middle = 0 ;
  917. X                        right = 0 ;
  918. X                        f_text.FrontPen = ORNP ;
  919. X                        break ;
  920. X
  921. X                        case 1:
  922. X                        barw = (WINW - (2 * BORDER)) - 1 ;
  923. X                        left = LEFT ;
  924. X                        middle = 0 ;
  925. X                        right = 0 ;
  926. X                        f_text.FrontPen = BLUP ;
  927. X                        break ;
  928. X
  929. X                        case 2:
  930. X                        barw = (WINW - (2 * BORDER)) - 1 ;
  931. X                        left = 0 ;
  932. X                        middle = LEFT ;
  933. X                        right = 0 ;
  934. X                        f_text.FrontPen = CYNP ;
  935. X                        break ;
  936. X
  937. X                        case 3:
  938. X                        barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ;
  939. X                        left = LEFT ;
  940. X                        middle = (left + barw + 1) ;
  941. X                        right = 0 ;
  942. X                        f_text.FrontPen = BLUP ;
  943. X                        break ;
  944. X
  945. X                        case 4:
  946. X                        barw = (WINW - (2 * BORDER)) - 1 ;
  947. X                        left = 0 ;
  948. X                        middle = 0;
  949. X                        right = LEFT ;
  950. X                        f_text.FrontPen = YELP ;
  951. X                        break ;
  952. X
  953. X                        case 5:
  954. X                        barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ;
  955. X                        left = LEFT ;
  956. X                        middle = 0 ;
  957. X                        right = (left + barw + 1) ;
  958. X                        f_text.FrontPen = CYNP ;
  959. X                        break ;
  960. X
  961. X                        case 6:
  962. X                        barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ;
  963. X                        left = 0 ;
  964. X                        middle = LEFT ;
  965. X                        right = (middle + barw + 1) ;
  966. X                        f_text.FrontPen = YELP ;
  967. X                        break ;
  968. X
  969. X                        case 7:
  970. X                        barw = ((WINW - (2 * BORDER)) / 3 ) - 1 ;
  971. X                        left = LEFT ;
  972. X                        middle = (left + barw + 1) ;
  973. X                        right = (middle + barw + 1) ;
  974. X                        f_text.FrontPen = BLUP ;
  975. X                        break ;
  976. X                        }  /* end of switch ( colflags ) */
  977. X                    }  /* end of if ( chgflag ) */
  978. X                cmemseg = cmemsize / barh ;
  979. X                sfmemseg = sfmemsize / barh ;
  980. X                fmemseg = fmemsize / barh ;
  981. X                if (mmode == TRUE && ((sfmemsize != 0) ||
  982. X                                      (fmembase != 0x200000)))  {
  983. X                    /* Keep your eyes open here.  If we get a negative    */
  984. X                    /* response from the requester, that means either the */
  985. X                    /* user retreated, or a no-requester function such as */
  986. X                    /* noreq or KillReq has selected the negative option. */
  987. X                    /* If such functions select the positive option they  */
  988. X                    /* force acceptance of the crash risk with SFmemory.  */
  989. X
  990. X                    mode = AutoRequest(window, &bodyText0, &positiveText,
  991. X                               &negativeText, 0L, 0L, 319L, 79L) ;
  992. X                    }
  993. X                if (mmode == TRUE && ((sfmemsize != 0) ||
  994. X                                      (fmembase != 0x200000)))  {
  995. X                    if (mode == FRAGS)  {      /* user Retreat select  */
  996. X                        sfmemseg = 0 ;         /* results in execution */
  997. X                        sfmemsize = 0 ;        /* of this code segment */
  998. X                        fmembase = 0x200000 ;  /* resetting internals  */
  999. X                        }
  1000. X                    }
  1001. X                switch ( wf ) {
  1002. X                    case 0:
  1003. X                    xl = left ;
  1004. X                    membase = cmembase ;
  1005. X                    memseg = cmemseg ;
  1006. X                    memsize = cmemsize ;
  1007. X                    break;
  1008. X
  1009. X                    case 1:
  1010. X                    xl = middle ;
  1011. X                    membase = sfmembase ;
  1012. X                    memseg = sfmemseg ;
  1013. X                    memsize = sfmemsize ;
  1014. X                    break;
  1015. X
  1016. X                    case 2:
  1017. X                    xl = right ;
  1018. X                    membase = fmembase ;
  1019. X                    memseg = fmemseg ;
  1020. X                    memsize = fmemsize ;
  1021. X                    break;
  1022. X                    }  /* end of switch ( wf ) */
  1023. X                xr = xl + barw ;
  1024. X                if (mmode == TRUE)  {
  1025. X                    mode = WARPS ;
  1026. X                    mmode = FALSE ;
  1027. X                    }
  1028. X                if (xl != 0)  {
  1029. X                    if (mode == WARPS)  {
  1030. X                        (void) updatewarps( wf, membase, memseg ) ;
  1031. X                        e_text.FrontPen = YELP ;
  1032. X                        }
  1033. X                    if (mode == FRAGS)  {
  1034. X                        (void) updatescreen( wf, membase, memseg ) ;
  1035. X                        e_text.FrontPen = BLUP ;
  1036. X                        }
  1037. X                    }
  1038. X                if (intsig == TRUE)  {
  1039. X                    handle_NEWSIZE() ;
  1040. X                    intsig = FALSE ;
  1041. X                    }
  1042. X                if (syspri != priority)  {
  1043. X                    syspri = priority ;
  1044. X                    nptr = NULL;
  1045. X                    mmtcb = FindTask( nptr ) ;
  1046. X                    oldpri = SetTaskPri( mmtcb, syspri ) ;
  1047. X                    }
  1048. X                if (wf == 2)  {
  1049. X                    PrintIText(window->RPort,&f_text,RTEXT,0L) ;
  1050. X                    wakeupbits = Wait(timerbit) ;
  1051. X                    if (wakeupbits & timerbit)  {
  1052. X                        GetMsg(timerport);
  1053. X                        SetTimer(delayval, 0L, timermsg);
  1054. X                        }
  1055. X                    }
  1056. X                wf++ ;
  1057. X                if (wf >= 3)  wf = 0 ;
  1058. X                } /* end of while ( things_are_cool) */
  1059. X
  1060. X            if (timerport) {
  1061. X                Wait(timerbit);
  1062. X                GetMsg(timerport);
  1063. X                CloseDevice(timermsg);
  1064. X                DeleteStdIO(timermsg);
  1065. X                DeletePort(timerport);
  1066. X                }
  1067. X
  1068. X            if (GfxBase)    CloseLibrary(GfxBase) ;
  1069. X            }
  1070. X        if (window)         CloseWindow(window) ;
  1071. X        if (IntuitionBase)  CloseLibrary(IntuitionBase) ;
  1072. X        }
  1073. X    wrack_sploot() ;
  1074. X}
  1075. X
  1076. X_cli_parse() {}
  1077. X_wb_parse() {}
  1078. END_OF_FILE
  1079. if test 35050 -ne `wc -c <'mm.c'`; then
  1080.     echo shar: \"'mm.c'\" unpacked with wrong size!
  1081. fi
  1082. # end of 'mm.c'
  1083. fi
  1084. echo shar: End of archive 2 \(of 2\).
  1085. cp /dev/null ark2isdone
  1086. MISSING=""
  1087. for I in 1 2 ; do
  1088.     if test ! -f ark${I}isdone ; then
  1089.     MISSING="${MISSING} ${I}"
  1090.     fi
  1091. done
  1092. if test "${MISSING}" = "" ; then
  1093.     echo You have unpacked both archives.
  1094.     rm -f ark[1-9]isdone
  1095. else
  1096.     echo You still need to unpack the following archives:
  1097.     echo "        " ${MISSING}
  1098. fi
  1099. ##  End of shell archive.
  1100. exit 0
  1101. -- 
  1102. Mail submissions (sources or binaries) to <amiga@cs.odu.edu>.
  1103. Mail comments to the moderator at <amiga-request@cs.odu.edu>.
  1104. Post requests for sources, and general discussion to comp.sys.amiga.
  1105.